from django.urls import path
from . import views, admin_views, export_views, qr_views, import_views
from django.conf import settings
from django.conf.urls.static import static

app_name = 'bike'

urlpatterns = [
    # 前台页面
    path('', views.bike_statistics, name='home'),
    path('bikes/', views.bike_list, name='bike_list'),
    path('detail/<int:bike_id>/', views.bike_detail, name='bike_detail'),
    path('statistics/', views.bike_statistics, name='bike_statistics'),
    path('violations/', views.violation_list, name='frontend_violation_list'),
    
    # 管理后台
    path('admin/login/', admin_views.admin_login, name='admin_login'),
    path('admin/logout/', admin_views.admin_logout, name='admin_logout'),
    path('admin/', admin_views.admin_dashboard, name='admin_dashboard'),
    path('admin/bikes/', admin_views.bike_list_admin, name='admin_bike_list'),
    path('admin/bikes/add/', admin_views.bike_add, name='admin_bike_add'),
    path('admin/bikes/edit/<int:bike_id>/', admin_views.bike_edit, name='admin_bike_edit'),
    path('admin/bikes/delete/<int:bike_id>/', admin_views.bike_delete, name='admin_bike_delete'),
    path('admin/bikes/batch-delete/', admin_views.batch_delete, name='batch_delete'),
    path('admin/bikes/batch-export-qr/', admin_views.batch_export_qr, name='batch_export_qr'),
    path('admin/violations/', admin_views.violation_list, name='violation_list'),
    path('admin/violations/update-status/<int:violation_id>/', admin_views.violation_update_status, name='violation_update_status'),
    path('admin/secret-key/', admin_views.secret_key_management, name='secret_key_management'),
    path('admin/users/', admin_views.user_management, name='user_management'),
    path('admin/users/add/', admin_views.user_add, name='user_add'),
    path('admin/users/edit/<int:user_id>/', admin_views.user_edit, name='user_edit'),
    path('admin/users/delete/<int:user_id>/', admin_views.user_delete, name='user_delete'),
    path('admin/export-qr/', admin_views.export_qr_codes, name='export_qr_codes'),
    
    # 批量导入功能
    path('admin/bikes/import/', import_views.bike_batch_import, name='bike_batch_import'),
    path('admin/bikes/import-template/', import_views.bike_import_template, name='bike_import_template'),
    
    # 手机端页面（二维码扫码进入）
    path('bike/<int:bike_id>/', admin_views.mobile_bike_detail, name='mobile_bike_detail'),
    path('bike/<str:bike_number>/', admin_views.mobile_bike_detail_by_number, name='mobile_bike_detail_by_number'),
    
    # 导出功能
    path('export/bikes/excel/', export_views.export_bikes_excel, name='export_bikes_excel'),
    path('export/bikes/csv/', export_views.export_bikes_csv, name='export_bikes_csv'),
    path('export/users/excel/', export_views.export_users_excel, name='export_users_excel'),
    path('export/violations/excel/', export_views.export_violations_excel, name='export_violations_excel'),
    
    # 二维码刷新功能
    path('admin/bikes/refresh-qr/<int:bike_id>/', qr_views.refresh_qr_code, name='refresh_qr_code'),
    path('admin/bikes/batch-refresh-qr/', qr_views.batch_refresh_qr, name='batch_refresh_qr'),
]

# 开发环境下提供媒体文件服务
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)